/*
	2007-2008 UMKC Robotics Team
	ATMega128 (CPU1) 
	
	Initializer File
	
	Updated: 2/1/08
	
	Created By: Jared Bayne
	E-Mail:		JaredNBayne@gmail.com
	Created On:	February 1st, 2008

	Purpose:	This file will initialize the ports


*/




void InitPorts(void);

//Misc Defines
#define		ON		1
#define		OFF		0


//Olimex Development Board Defines
#define	LED	GET_BIT(PORTA).bit6


// Define the bits in the port 
typedef struct 
{ 
   unsigned char bit0 : 1, 
                 bit1 : 1, 
                 bit2 : 1, 
                 bit3 : 1, 
                 bit4 : 1, 
                 bit5 : 1, 
                 bit6 : 1, 
                 bit7 : 1; 
} bit_field; 

// Define macro to get the value of each bit 
#define GET_BIT(port) (*(volatile bit_field *) (_SFR_ADDR(port))) 

/* EXAMPLE Define functions for each bit of the I/O ports in the program 
#define SIG    GET_BIT(PINB).bit0	//Notice, input uses "PINB"
#define LED	   GET_BIT(PORTD).bit0	//Notice, output uses PORTB
*/


void InitPorts(void)
{
	/* Port A initialization
	%1100 0000 (1=OUT 0=IN)
	Buttons on Development Board
	PA6 = onboard LED
	PA7 = CPU3Add3
	*/
	PORTA=0x00;
	DDRA=0xC0; // 192/255
	
	/* Port B initialization
	%1111 1111 (1=OUT 0=IN)
	PB0 = CPU2Add6
	PB2 = M2C1
	PB3 = CPU3Add1
	PB4 = M1C1
	PB5 = M1C2
	PB6 = M2C2
	
	*/
	PORTB=0x00;
	DDRB=0xFF;   // 255/255

	/* Port C initialization
	%1111 1111 (1=OUT 0=IN)
	LCD Screen on Development Board
	PC3 = CPU3Add2
	*/
	PORTC=0x00;
	DDRC=0xFF;

	/*Port D Initilializtion
	%1111 1001  (1=OUT 0=IN)
	PD1 = CPU2Data
	PD2 = RXD1	 // reciever
	PD3 = TXD1   // transmiter
	PD4 = CPU2Add3
	PD5 = CPU2Add4	
	*/
	PORTD=0x00;
	DDRD=0xF9;
	
	/* Port E initialization
	%1000 1111 (1=OUT 0=IN)
	PE2 = CPU2ADD1
	PE3 = CPU2Add2
	PE7 = CPU3Add4
	*/
	PORTE=0x00;    // buzzer
	DDRE=0x8F;		// buzzer 143/255

	/* Port F initialization
	%1111 0000 (1=OUT 0=IN)
	
	*/
	PORTF=0x00;
	DDRF=0xF0;

	/* Port G initialization
	%1111 1111 (1=OUT 0=IN)
	
	*/
	PORTG=0x00;
	DDRG=0x00;

}
